function convertCMUToKK(cmuPhonemes) {
  // CMU到KK音标映射表
  const phonemeMap = {
    // 元音
    'AA': 'ɑ',   'AA0': 'ə',   'AA1': 'ɑ',   'AA2': 'ʌ',
    'AE': 'æ',   'AE0': 'ə',   'AE1': 'æ',   'AE2': 'ʌ',
    'AH': 'ʌ',   'AH0': 'ə',   'AH1': 'ʌ',   'AH2': 'ʌ',
    'AO': 'ɔ',   'AO0': 'ə',   'AO1': 'ɔ',   'AO2': 'ʌ',
    'AW': 'aʊ',  'AW0': 'aʊ',  'AW1': 'aʊ',  'AW2': 'aʊ',
    'AX': 'ə',   'AX0': 'ə',   'AX1': 'ə',   'AX2': 'ə',
    'AXR': 'ɚ',  'AXR0': 'ɚ',  'AXR1': 'ɚ',  'AXR2': 'ɚ',
    'AY': 'aɪ',  'AY0': 'aɪ',  'AY1': 'aɪ',  'AY2': 'aɪ',
    
    // 双元音
    'EH': 'ɛ',   'EH0': 'ə',   'EH1': 'ɛ',   'EH2': 'ʌ',
    'ER': 'ɝ',   'ER0': 'ɚ',   'ER1': 'ɝ',   'ER2': 'ɚ',
    'EY': 'eɪ',  'EY0': 'eɪ',  'EY1': 'eɪ',  'EY2': 'eɪ',
    
    'IH': 'ɪ',   'IH0': 'ɪ',   'IH1': 'ɪ',   'IH2': 'ɪ',
    'IR': 'ɪr',  'IR0': 'ɪr',  'IR1': 'ɪr',  'IR2': 'ɪr',
    'IY': 'i',   'IY0': 'i',   'IY1': 'i',   'IY2': 'i',
    
    'OW': 'oʊ',  'OW0': 'oʊ',  'OW1': 'oʊ',  'OW2': 'oʊ',
    'OY': 'ɔɪ',  'OY0': 'ɔɪ',  'OY1': 'ɔɪ',  'OY2': 'ɔɪ',
    
    'UH': 'ʊ',   'UH0': 'ʊ',   'UH1': 'ʊ',   'UH2': 'ʊ',
    'UW': 'u',   'UW0': 'u',   'UW1': 'u',   'UW2': 'ʊ',
    
    // 辅音
    'B': 'b',    'CH': 'tʃ',   'D': 'd',     'DH': 'ð',
    'F': 'f',    'G': 'ɡ',     'HH': 'h',    'JH': 'dʒ',
    'K': 'k',    'L': 'l',     'M': 'm',     'N': 'n',
    'NG': 'ŋ',   'P': 'p',     'R': 'r',     'S': 's',
    'SH': 'ʃ',   'T': 't',     'TH': 'θ',    'V': 'v',
    'W': 'w',    'Y': 'j',     'Z': 'z',     'ZH': 'ʒ'
  };

  // 弱读形式映射
  const weakForms = {
    'AH0': 'ə', 'AA0': 'ə', 'AO0': 'ə', 'EH0': 'ə', 
    'ER0': 'ɚ', 'IH0': 'ɪ', 'UH0': 'ə', 'UW0': 'ə',
    'AE0': 'ə', 'IY0': 'ɪ', 'EY0': 'ɪ', 'OW0': 'ə',
    'AW0': 'ə', 'AY0': 'ə', 'UH0': 'ə'
  };

  // 重音符号映射
  const stressMarks = {
    '0': '',    // 无重音
    '1': 'ˈ',   // 主重音
    '2': 'ˌ'    // 次重音
  };

  // 特殊组合规则
  const specialRules = {
    'TR': 'tʃɹ',
    'DR': 'dʒɹ',
    'L_END': 'ɫ'
  };

  // 用于存储结果
  let result = '';
  let syllables = [];
  let currentSyllable = [];

  // 分割音节
  function splitIntoSyllables() {
    let vowelIndices = [];
    for (let i = 0; i < cmuPhonemes.length; i++) {
      const phoneme = cmuPhonemes[i];
      const base = phoneme.replace(/[0-9]/g, '');
      if (/[AEIOU]/.test(base)) {
        vowelIndices.push(i);
      }
    }

    if (vowelIndices.length === 0) return [];

    let syllableBoundaries = [0];
    for (let i = 0; i < vowelIndices.length - 1; i++) {
      const mid = Math.floor((vowelIndices[i] + vowelIndices[i + 1]) / 2);
      syllableBoundaries.push(mid);
    }
    syllableBoundaries.push(cmuPhonemes.length);

    return syllableBoundaries;
  }

  // 处理单个音节
  function processSyllable(start, end, primaryStressIndex) {
    let syllableResult = '';
    let stressMark = '';
    let hasVowel = false;

    for (let i = start; i < end; i++) {
      const phoneme = cmuPhonemes[i];
      const base = phoneme.replace(/[0-9]/g, '');
      const stress = phoneme.match(/[0-9]/)?.[0] || '0';
      const key = `${base}${stress}`;
      
      let kkPhoneme = weakForms[key] || phonemeMap[key] || phonemeMap[base];
      if (!kkPhoneme) kkPhoneme = base;

      if (stress !== '0') {
        stressMark = stressMarks[stress];
      }

      // 处理 TR/DR 组合
      if (i < end - 1) {
        const nextPhoneme = cmuPhonemes[i + 1];
        const nextBase = nextPhoneme.replace(/[0-9]/g, '');
        if (base === 'T' && nextBase === 'R') {
          syllableResult += 'tʃɹ';
          i++;
          continue;
        } else if (base === 'D' && nextBase === 'R') {
          syllableResult += 'dʒɹ';
          i++;
          continue;
        }
      }

      // 末尾 L 发暗音
      if (base === 'L' && i === end - 1) {
        syllableResult += 'ɫ';
        continue;
      }

      // 判断是否为元音
      if (/[ɑæʌɔaʊəɚɛeɪɪɔɪoʊʊu]/.test(kkPhoneme)) {
        hasVowel = true;
      }

      syllableResult += kkPhoneme;
    }

    // 如果没有元音，强制添加一个弱读音
    if (!hasVowel && syllableResult.length > 0) {
      syllableResult += 'ə';
    }

    return { syllableResult, stressMark };
  }

  // 分割音节边界
  const boundaries = splitIntoSyllables();
  if (boundaries.length < 2) {
    // 如果无法分割音节，直接转换
    return cmuPhonemes.map(p => {
      const base = p.replace(/[0-9]/g, '');
      const stress = p.match(/[0-9]/)?.[0] || '0';
      const key = `${base}${stress}`;
      return stressMarks[stress] + (phonemeMap[key] || phonemeMap[base] || base);
    }).join('');
  }

  // 处理每个音节
  for (let i = 0; i < boundaries.length - 1; i++) {
    const start = boundaries[i];
    const end = boundaries[i + 1];
    const syllableInfo = processSyllable(start, end);
    result += syllableInfo.stressMark + syllableInfo.syllableResult;
  }

  return result;
}


function arpabetToKk(word) {
  let cmuword = CMUdictionary[word]
  if(!cmuword) return {[word]: {kk_no_space:''}};
  const cmuPhonemes = cmuword.split(' ');
  let result ={[word]: {kk_no_space:`/${convertCMUToKK(cmuPhonemes)}/`}};
  return result
}
